package com.gxpt.app.view;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.gxpt.app.AppUtils;
import com.gxpt.app.BaseActivity;
import com.gxpt.app.Constant;
import com.gxpt.app.MessageEvent;
import com.gxpt.app.R;
import com.gxpt.app.bean.complete_bean;
import com.gxpt.app.bean.demanddetail_bean;
import com.gxpt.app.bean.isstore_bean;
import com.gxpt.app.bean.normal;
import com.gxpt.app.bean.tuoguanorder_bean;
import com.gxpt.app.bean.ykjtgorder_bean;
import com.utils.T;
import com.utils.logger.Logger;
import com.utils.okhttputils.HttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import okhttp3.Call;

/**
 * Created by dufeng on 2017/8/4.
 */

@ContentView(R.layout.activity_life_need_detail)
public class Activity_life_need_detail extends BaseActivity {


    @ViewInject(R.id.toback)
    Button toback;

    @ViewInject(R.id.txt_title)
    TextView txt_title;

    @ViewInject(R.id.txt_d_title)
    TextView txt_d_title;

    @ViewInject(R.id.txt_price)
    TextView txt_price;

    @ViewInject(R.id.txt_identity)
    TextView txt_identity;

    @ViewInject(R.id.txt_bid_count)
    TextView txt_bid_count;

    @ViewInject(R.id.txt_name)
    TextView txt_name;


    @ViewInject(R.id.txt_info)
    TextView txt_info;

    @ViewInject(R.id.txt_description)
    TextView txt_description;

    @ViewInject(R.id.txt_views)
    TextView txt_views;

    @ViewInject(R.id.alert)
    TextView alert;


    @ViewInject(R.id.ck_store)
    CheckBox ck_store;

    @ViewInject(R.id.toStoreMy)
    LinearLayout toStoreMy;

    @ViewInject(R.id.toUserHomePage)
    RelativeLayout toUserHomePage;

    @ViewInject(R.id.toServicelist)
    LinearLayout toServicelist;
///////////////////////////////////////////////
    @ViewInject(R.id.STUTS)
    TextView STUTS;

    @ViewInject(R.id.tobid)
    TextView tobid;

    @ViewInject(R.id.toClose)
    TextView toClose;

    @ViewInject(R.id.toCreate)
    TextView toCreate;

    @ViewInject(R.id.toHetong)
    TextView toHetong;

    @ViewInject(R.id.tozhuijiayusuan)
    TextView tozhuijiayusuan;

    @ViewInject(R.id.tozijintuoguan)
    TextView tozijintuoguan;

    @ViewInject(R.id.toquerenwancheng)
    TextView toquerenwancheng;

    @ViewInject(R.id.toduifuwushangpingjia)
    TextView toduifuwushangpingjia;

    @ViewInject(R.id.toquerenwancheng_yf)
    TextView toquerenwancheng_yf;

    @ViewInject(R.id.toHetong_yf)
    TextView toHetong_yf;

    @ViewInject(R.id.had_bid)
    TextView had_bid;

    @ViewInject(R.id.do_ING)
    TextView do_ING;

    @ViewInject(R.id.do_complete_alt)
    TextView do_complete_alt;

    @ViewInject(R.id.do_complete_alt_finish)
    TextView do_complete_alt_finish;

    @ViewInject(R.id.finish_jia)
    TextView finish_jia;


    @ViewInject(R.id.view1)
    LinearLayout view1; //pt

    @ViewInject(R.id.view2)
    LinearLayout view2;//stuts

    @ViewInject(R.id.view3)
    LinearLayout view3;//甲方

    @ViewInject(R.id.view4)
    LinearLayout view4;//乙方

    @ViewInject(R.id.view5)
    LinearLayout view5;//乙方

    @ViewInject(R.id.show_info)
    TextView show_info;

    @ViewInject(R.id.toSelect_bid_jia)
    TextView toSelect_bid_jia;//甲方

    @ViewInject(R.id.alt_had_hetong)
    TextView alt_had_hetong;//乙方

    @ViewInject(R.id.alt_jiafang_money_tuoguan)
    TextView alt_jiafang_money_tuoguan;//乙方

    @ViewInject(R.id.create_time_alt_yf)
    TextView create_time_alt_yf;//乙方

    @ViewInject(R.id.alt_had_hetong_jf)
    TextView alt_had_hetong_jf;//甲方



    String ID=null;
    String member_id = null;

    int FORM = 0;

    int stuts      = 0;//        需求状态 0未审核1已审核2已驳回3已关闭
    int bid_status = 0;//        竞标状态 1投标中2已中标3待网签4已网签5实施中6已流标7已完成

    boolean isSingedHetong = false;//是否已经网签合同

    String bid_id = "";
    String project_amount = "";

    String yikoujia_is = "0";//0一口价
    float yikoujia_amount = 0;

    //stage：总的阶段数  stage_num：第几阶段
    int stage =0;
    int stage_num=0;
    int stage_status=0;//阶段完成状态 0未完成1已完成

    int bid_count;//竞标人数

    int is_time=0;//是否创建了工期
    int stage_pay_status = 0;//本阶段是否托管了资金
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
        ID     = ""+getIntent().getIntExtra("ID",0);
        FORM   = getIntent().getIntExtra("FORM",0);
        x.view().inject(this);
        initView();
        initData();
}

    @Override
    protected void onDestroy() {
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMoonEvent(MessageEvent messageEvent){
        switch (messageEvent.getMessageType()){
            case Constant.ACTION_pay_success:
            case Constant.ACTION_hetong_siged:
            case Constant.ACTION_to_gq_submit:
            case Constant.ACTION_bid_success:
            case Constant.ACTION_assess:
                toNet_demanddetail();
                break;

        }
    }

    @Override
    public void initView() {
        txt_title.setText(getString(R.string.txt_xuqiuxiangqing));
//        if(FORM == Constant.F_MYSELF){
//            view1.setVisibility(View.GONE);
//            view3.setVisibility(View.VISIBLE);
//            view4.setVisibility(View.GONE);
//        }else if(FORM == Constant.F_MYTAKE){
//            view1.setVisibility(View.GONE);
//            view3.setVisibility(View.GONE);
//            view4.setVisibility(View.VISIBLE);
//        }else{
//            view1.setVisibility(View.VISIBLE);
//            view3.setVisibility(View.GONE);
//            view4.setVisibility(View.GONE);
//        }
    }

    private void reload_myself(){
        initData();
    }



    @Override
    public void initData() {
        if(ID != null){
            toNet_demanddetail();
        }

    }

    private void setData(demanddetail_bean.demanddetail d){
        //init
        member_id = "";
        bid_id    = "";
        project_amount = "";
        stage =0;
        stage_num=0;
        stage_status=0;
        yikoujia_amount= 0;
        yikoujia_is = "";
        bid_count = 0;
        is_time=0;
        stage_pay_status = 0;

        view1.setVisibility(View.GONE);
        view2.setVisibility(View.GONE);
        view3.setVisibility(View.GONE);
        view4.setVisibility(View.GONE);
        STUTS.setVisibility(View.GONE);

        had_bid.setVisibility(View.GONE);
        toHetong_yf.setVisibility(View.GONE);
        toquerenwancheng_yf.setVisibility(View.GONE);
        do_complete_alt.setVisibility(View.GONE);
        do_complete_alt_finish.setVisibility(View.GONE);

        tobid.setVisibility(View.GONE);
        tozijintuoguan.setVisibility(View.GONE);
        toClose.setVisibility(View.GONE);
        toCreate.setVisibility(View.GONE);
        toHetong.setVisibility(View.GONE);
        do_ING.setVisibility(View.GONE);
        toduifuwushangpingjia.setVisibility(View.GONE);
        toquerenwancheng.setVisibility(View.GONE);
        finish_jia.setVisibility(View.GONE);
        toSelect_bid_jia.setVisibility(View.GONE);
        alt_had_hetong.setVisibility(View.GONE);
        alt_jiafang_money_tuoguan.setVisibility(View.GONE);
        create_time_alt_yf.setVisibility(View.GONE);
        alt_had_hetong_jf.setVisibility(View.GONE);

        member_id = d.member_id;
        bid_id = d.bid_id;
        project_amount = d.project_amount;

        bid_count = Integer.parseInt(d.bid_count);
        is_time = d.is_time;
        stage_pay_status = Integer.parseInt(d.stage_pay_status);
        if(!d.stage.isEmpty()){

            stage     = Integer.parseInt(d.stage);
        }
        if(!d.stage_num.isEmpty()){

            stage_num     = Integer.parseInt(d.stage_num);
        }
        if(!d.stage_status.isEmpty()){

            stage_status     = Integer.parseInt(d.stage_status);
        }
//        try{
//            stage     = Integer.parseInt(d.stage);
//            stage_num = Integer.parseInt(d.stage_num);
//            stage_status = Integer.parseInt(d.stage_status);
//        }catch (Exception e){
//            stage     = 0;
//            stage_num = 0;
//            stage_status = 0;
//        }


        txt_d_title.setText(d.title);
        txt_price.setText(d.project_amount+getResources().getString(R.string.txt_yuan));
        yikoujia_amount = Float.parseFloat(d.project_amount);//传递变量
        txt_bid_count.setText(d.bid_count);

        txt_name.setText(d.mem_tel);
        txt_info.setText(d.create_time+getResources().getString(R.string.txt_fabuyu));
        txt_info.append(d.area_name);

        alert.setText(AppUtils.getJYMS(d.bidding_model));
        yikoujia_is = d.bidding_model;

        txt_description.setText(d.description);
        txt_views.setText(d.views);

        if(d.store_status.equals("0")){
            ck_store.setChecked(true);
        }else{
            ck_store.setChecked(false);
        }

        if(d.identity.equals("0")){
            txt_identity.setText(getResources().getString(R.string.txt_xuqiufang));
        }else{
            txt_identity.setText(getResources().getString(R.string.txt_zhongjianshang));
        }

        /**
         * view1  普通用户
         *
           view2  状态
           view3  需求方

           view4  服务方
         *
         * **/


        //当前登录用户是否是服务商 0不是2是
            if(d.member_id.equals(""+AppUtils.get_user_id(context))){
//                Logger.i(" = 需求方");
                view1.setVisibility(View.GONE);

                view2.setVisibility(View.VISIBLE);//状态
                view3.setVisibility(View.VISIBLE);

                view4.setVisibility(View.GONE);
            }else{//不是需求方，普通用户
//                 Logger.i(" = 非需求方");
                 view1.setVisibility(View.VISIBLE);

                 view2.setVisibility(View.GONE);//状态
                 view3.setVisibility(View.GONE);

                 view4.setVisibility(View.VISIBLE);

            }

        //view2
        if(!d.status.isEmpty()){
            stuts = Integer.parseInt(d.status);
            switch (stuts){
                case 0:
                    STUTS.setText(getString(R.string.txt_weishenhe));
                    STUTS.setVisibility(View.VISIBLE);
                    break;
                case 1:
                    STUTS.setText(getString(R.string.txt_shenhetongguo));
                    STUTS.setVisibility(View.VISIBLE);
                    break;
                case 2:
                    STUTS.setText(getString(R.string.txt_yibohui));
                    STUTS.setVisibility(View.VISIBLE);
                    break;
                case 3:
                    STUTS.setText(getString(R.string.txt_yiguanbi));
                    STUTS.setVisibility(View.VISIBLE);
                    break;
            }
        }


        //服务方
        if(!d.member_id.equals(""+AppUtils.get_user_id(context))){

            if(d.is_quot == 0){//服务商是否填写了报价 0未填写1已填写
                view1.setVisibility(View.VISIBLE);
                view4.setVisibility(View.GONE);
                had_bid.setVisibility(View.GONE);
            }else{//已经填写了报价
                view1.setVisibility(View.GONE);
                view4.setVisibility(View.VISIBLE);
                had_bid.setVisibility(View.VISIBLE);

                if(d.service_bid_status == 0 ){//服务商是否被选中标 0未中标1已中标
                    had_bid.setVisibility(View.VISIBLE);
                }else{//已中标
                    had_bid.setVisibility(View.GONE);
                    if(!d.bid_status.isEmpty()){

                        bid_status = Integer.parseInt(d.bid_status);

                        switch (bid_status){//1投标中2已中标3待网签4已网签5实施中6已流标7已完成
                            case 1:
                                break;
                            case 2:
                                if(is_time==0){//是否创建工期
                                    create_time_alt_yf.setVisibility(View.VISIBLE);
                                }else{
                                    toHetong_yf.setVisibility(View.VISIBLE);
                                }
                                break;
                            case 3:
                                if(d.contact_status == 0){//网签合同状态 0未签1已签
                                    toHetong_yf.setVisibility(View.VISIBLE);
                                    isSingedHetong = false;
                                }else{
                                    isSingedHetong = true;
                                    toHetong_yf.setVisibility(View.GONE);
                                    alt_had_hetong.setVisibility(View.VISIBLE);
                                }
                                break;
                            case 4:
                                if(d.bidding_model.equals("0")){//竞标模式 0一口价1招标

                                }else{
                                    alt_had_hetong.setVisibility(View.GONE);
                                    if(stage_pay_status == 1){
                                        alt_jiafang_money_tuoguan.setVisibility(View.GONE);
                                        if(stage_status==1){//阶段完成状态 0未完成1已完成
                                            do_complete_alt.setVisibility(View.VISIBLE);//等待甲方支付本阶段
                                        }else{
                                            toquerenwancheng_yf.setText(getResources().getString(R.string.txt_querenwangcheng_jieduan_yf));
                                            toquerenwancheng_yf.setVisibility(View.VISIBLE);
                                        }


                                    }else{
                                        alt_jiafang_money_tuoguan.setVisibility(View.VISIBLE);
                                    }
                                }
                                break;
                            case 5://实施中
                                if(stage_status == 1){//阶段完成状态 0未完成1已完成
                                    if(d.is_confirm == 1){//甲方是否确认支付 0未确认1已确认

                                    }else{
                                        do_complete_alt.setVisibility(View.VISIBLE);//等待甲方支付本阶段
                                    }
                                }else{//
                                    if(stage == stage_num){
                                        toquerenwancheng_yf.setText(getResources().getString(R.string.txt_xiangmuwancheng));
                                        toquerenwancheng_yf.setVisibility(View.VISIBLE);
                                    }else{
                                        toquerenwancheng_yf.setText(getResources().getString(R.string.txt_querenwangcheng_jieduan_yf));
                                        toquerenwancheng_yf.setVisibility(View.VISIBLE);
                                    }
                                }
                                break;
                            case 7:
                                if(d.is_confirm == 0 ){
                                    do_complete_alt.setVisibility(View.VISIBLE);
                                }else{
                                    do_complete_alt_finish.setVisibility(View.VISIBLE);
                                }

                                break;
                        }
                    }


                }


            }

        }




        //甲方
        if(!d.bid_status.isEmpty()){//竞标状态 1投标中2已中标3待网签4已网签5实施中6已流标7已完成
            bid_status = Integer.parseInt(d.bid_status);
//            Logger.i("竞标状态 = "+ bid_status);

            if(bid_status == 1 || bid_status == 0){//是否显示竞标按钮
                tobid.setVisibility(View.VISIBLE);
            }else{
                tobid.setVisibility(View.GONE);
            }

            if(d.member_id.equals(""+AppUtils.get_user_id(context))){

                if(d.bidding_model.equals("0")){//bidding_model 	int 	竞标模式 0一口价1招标

                    if(d.pay_status.equals("0")){//支付状态  0未付款1已付款2已取消
                        tozijintuoguan.setVisibility(View.VISIBLE);
                    }else{
                        tozijintuoguan.setVisibility(View.GONE);
                    }
                    switch (bid_status){
                        case 0:
                        case 1:
                            if(bid_count>0){//如果竞标人数大于1
                                toSelect_bid_jia.setVisibility(View.VISIBLE);
                            }
                            toClose.setVisibility(View.VISIBLE);
                            break;
                        case 2:
                            toCreate.setVisibility(View.VISIBLE);
                            break;
                        case 3://网签合同状态 0未签1已签
                            if(is_time==0){//是否创建工期
                                toCreate.setVisibility(View.VISIBLE);
                            }else{
                                if(d.contact_status == 0){//网签合同状态 0未签1已签
                                    isSingedHetong = false;
                                    toHetong.setVisibility(View.VISIBLE);
                                }else{
                                    isSingedHetong = true;
                                    toHetong.setVisibility(View.GONE);
                                    STUTS.setText(getResources().getString(R.string.txt_dengdaiyifangqianshuhetong));
                                    alt_had_hetong_jf.setVisibility(View.VISIBLE);
                                }
                            }
                            break;
                        case 4:
                            tozijintuoguan.setVisibility(View.VISIBLE);
                            tozhuijiayusuan.setVisibility(View.VISIBLE);
                            break;
                        case 5:
                            if(stage_status == 1){//阶段完成状态 0未完成1已完成

                                if(stage_pay_status == 1){//阶段支付状态 0未支付1已支付

                                }else {
                                    if(stage == stage_num){
                                        toquerenwancheng.setVisibility(View.VISIBLE);
                                    }else{
                                        toquerenwancheng.setText(getResources().getString(R.string.txt_querenwangcheng_jieduan_jf));
                                        toquerenwancheng.setVisibility(View.VISIBLE);
                                    }
                                }

                            }else{//
                                do_ING.setVisibility(View.VISIBLE);//实施中
                            }
                            break;
                        case 6:
                            toClose.setVisibility(View.VISIBLE);
                            break;
                        case 7:
                            if(d.is_confirm==1){//已经确认
                                if(d.evaluate_status == 1){
                                    toduifuwushangpingjia.setVisibility(View.GONE);//对服务商评价
                                    finish_jia.setVisibility(View.VISIBLE);
                                }else{
                                    toduifuwushangpingjia.setVisibility(View.VISIBLE);//对服务商评价
                                }

                            }else{//未确认
                                toquerenwancheng.setVisibility(View.VISIBLE);//确认支付按钮
                            }

                            break;
                    }


                }else{//招标  1投标中2已中标3待网签4已网签5实施中6已流标7已完成

                    switch (bid_status){
                        case 0:
                        case 1:
                            if(bid_count>0){//如果竞标人数大于1
                                toSelect_bid_jia.setVisibility(View.VISIBLE);
                            }
                            toClose.setVisibility(View.VISIBLE);
                            break;
                        case 2:
                            toCreate.setVisibility(View.VISIBLE);
                            break;
                        case 3://网签合同状态 0未签1已签
                            if(is_time==0){//是否创建工期
                                toCreate.setVisibility(View.VISIBLE);
                            }else{
                                if(d.contact_status == 0){//网签合同状态 0未签1已签
                                    isSingedHetong = false;
                                    toHetong.setVisibility(View.VISIBLE);
                                }else{
                                    isSingedHetong = true;
                                    toHetong.setVisibility(View.GONE);
                                    STUTS.setText(getResources().getString(R.string.txt_dengdaiyifangqianshuhetong));
                                }
                            }
                            break;
                        case 4:
                            tozhuijiayusuan.setVisibility(View.VISIBLE);

                             if(stage_pay_status == 1){//0未支付1已支付
                                 tozijintuoguan.setVisibility(View.GONE);

                                 if(stage_status == 1){//阶段完成状态 0未完成1已完成
                                     if(d.is_confirm == 0){
                                         toquerenwancheng.setText(getResources().getString(R.string.txt_querenwangcheng_jieduan_jf));
                                         toquerenwancheng.setVisibility(View.VISIBLE);

                                         tozhuijiayusuan.setVisibility(View.GONE);
                                     }else{
                                         toquerenwancheng.setVisibility(View.GONE);
                                     }
                                 }else{

                                 }

                             }else{
                                 tozijintuoguan.setVisibility(View.VISIBLE);
                             }

                            break;
                        case 5:
                            if(stage_pay_status ==0){
                                tozhuijiayusuan.setVisibility(View.VISIBLE);
                            }else{

                            }

                            break;
                        case 6:
                            toClose.setVisibility(View.VISIBLE);
                            break;
                        case 7:
                            if(d.is_confirm==1) {//甲方已经确认
                                if(d.evaluate_status == 1){//甲方是否对服务商进行了评价 0未评1已评
                                    toduifuwushangpingjia.setVisibility(View.GONE);//对服务商评价
                                    finish_jia.setVisibility(View.VISIBLE);
                                }else{
                                    toduifuwushangpingjia.setVisibility(View.VISIBLE);//对服务商评价
                                }
                            }else{
                                toquerenwancheng.setVisibility(View.VISIBLE);//确认支付按钮
                            }
                            break;
                    }
                }


            }


        }




    }

    @Event(value={R.id.toback,R.id.toStoreMy,R.id.toUserHomePage,R.id.toServicelist,R.id.tobid,
                    R.id.toClose,R.id.toHetong,R.id.toduifuwushangpingjia,
                    R.id.toquerenwancheng,R.id.tozijintuoguan,R.id.toCreate,R.id.tozhuijiayusuan,
                    R.id.toHetong_yf,R.id.toquerenwancheng_yf,R.id.toSelect_bid_jia})
    private void getEvent(View view){
        switch(view.getId()){
            case R.id.toback:
                closeActivity();
                break;
            case R.id.toStoreMy:
                if(AppUtils.get_user_id(context)>0){
                toNet_addstore();
                }else{
                    Intent go = new Intent();
                    go.setClass(context,Activity_login.class);
                    startActivity(go);
                }
                break;
            case R.id.toUserHomePage:
                Bundle b = new Bundle();
                b.putString("ID",member_id);
                jumpActivity(Activity_life_user_detail.class,b,false);
                break;
            case R.id.toSelect_bid_jia:
            case R.id.toServicelist:
                if(member_id.equals(""+AppUtils.get_user_id(context))){
                    Bundle c = new Bundle();
                    c.putString("member_ID", member_id);
                    c.putInt   ("BID_STUTS", bid_status);//判断是不是1，是1就可以拍标
                    c.putString("ID",        ID);
                    c.putInt("FORM",         FORM);//来源
                    jumpActivity(Activity_bid_servicelist.class,c,false);
                }

                break;
            case R.id.tobid:
                if(AppUtils.get_user_id(context)>0){
                    Bundle d = new Bundle();
                    d.putString("ID",ID);
                    d.putString("yikoujia_is",yikoujia_is);//一口价
                    d.putFloat("yikoujia_amount",yikoujia_amount);//一口价
                    jumpActivity(Activity_life_service_partbid.class,d,false);
                }else{
                    Intent go = new Intent();
                    go.setClass(context,Activity_login.class);
                    startActivity(go);
                }

                break;
            case R.id.toClose:
                Dialog_y_n();
                break;
            case R.id.toHetong:
                if(isSingedHetong == false){
                    Bundle h = new Bundle();
                    h.putString("ID",ID);
                    h.putInt("TYPE",1);
                    jumpActivity(Activity_webview_showcontact.class,h,false);
                }

                break;
            case R.id.toHetong_yf:
                if(isSingedHetong == false){
                    Bundle h2 = new Bundle();
                    h2.putString("ID",ID);
                    h2.putInt("TYPE",2);
                    jumpActivity(Activity_webview_showcontact.class,h2,false);
                }

                break;
            case R.id.toduifuwushangpingjia://对服务商评价
                Bundle b2 = new Bundle();
                b2.putString("column_id",""+bid_id);
                jumpActivity(Activity_evaluate_life.class,b2,true);
                break;
            case R.id.toquerenwancheng://确认完成支付
                toNet_jiaconfirmpay();
                break;
            case R.id.tozijintuoguan:
                if(yikoujia_is.equals("0")){//一口价
                    toNet_ykjtgorder();

                }else{//招标
                    toNet_tuoguanorder("");
                }
                break;
            case R.id.toCreate:
                Bundle tc = new Bundle();
                tc.putString("demand_id"       ,ID);
                tc.putString("bid_id"          ,bid_id);
                tc.putDouble("project_amount"  ,Double.parseDouble(project_amount));
                jumpActivity(Activity_createtime_main.class,tc,false);
                break;
            case R.id.tozhuijiayusuan:
                Dialog_zhuijia();
                break;
            case R.id.toquerenwancheng_yf:
                toNet_complete();
                break;
        }
    }

    public void Dialog_y_n(){
        final Dialog dialog=new Dialog(context,R.style.customDialogStyle);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view= LayoutInflater.from(context).inflate(R.layout.dialog_y_n, null);
        dialog.setContentView(view);
        view.findViewById(R.id.bt1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toNet_closedemand();
                dialog.dismiss();
            }
        });

        view.findViewById(R.id.bt2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        view.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        Window dialogWindow = dialog.getWindow();
        dialogWindow.setWindowAnimations(R.style.commonAnimDialogStyle);
        dialogWindow.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        dialogWindow.setGravity(Gravity.BOTTOM);
        dialog.show();

    }


    public void Dialog_zhuijia(){
        final Dialog dialog=new Dialog(context,R.style.customDialogStyle);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view= LayoutInflater.from(context).inflate(R.layout.dialog_tuoguanorder, null);
        dialog.setContentView(view);

        final EditText editText = (EditText)view.findViewById(R.id.editText);


        view.findViewById(R.id.toSure).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String ddd = editText.getText().toString();
                toNet_tuoguanorder(ddd);
                dialog.dismiss();
            }
        });

        view.findViewById(R.id.toCancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        Window dialogWindow = dialog.getWindow();
        dialogWindow.setWindowAnimations(R.style.commonAnimDialogStyle);
        dialogWindow.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        dialogWindow.setGravity(Gravity.BOTTOM);
        dialog.show();

    }


    //////NET DO
    StringCallback do_demanddetail = new StringCallback(){


        @Override
        public void onError(Call call, Exception e, int i) {
            Logger.e(e.getMessage());
        }

        @Override
        public void onResponse(String s, int i) {
            if(hud.isShowing()){
                hud.dismiss();
            }
            Logger.e("需求详情"+s);
            try{
                demanddetail_bean data = new Gson().fromJson(s, demanddetail_bean.class);

                if(data.state !=1 ){
                    T.show(context,data.msg,0);
                }else{
                    setData(data.data);
                }
            }catch (Exception e){
                e.printStackTrace();
                T.show(context,getResources().getString(R.string.alert_again),0);
            }
        }
    };

//    /////NET
    private void toNet_demanddetail(){
        hud.show();
          JSONObject jsonBody=new JSONObject();
        try {
            jsonBody.put("device_number",         AppUtils.get_device_id(context));
            jsonBody.put("device_type",           Constant.device_type);
            jsonBody.put("token",                 AppUtils.get_token(context));
            jsonBody.put("pageName",             "demand");
            jsonBody.put("serviceName",          "demanddetail");

            jsonBody.put("member_id",            AppUtils.get_user_id(context));
            jsonBody.put("id",                   ID);


        } catch (JSONException e) {
            e.printStackTrace();
        }
//        Logger.i(jsonBody.toString()+" ==["+Constant.URL_demanddetail+" ]");
        HttpUtils.http_post_string(Constant.URL_demanddetail,jsonBody.toString(),do_demanddetail);
    }


    private void toNet_isstore(){//是否收藏
        JSONObject jsonBody=new JSONObject();
        try {
            jsonBody.put("device_number",         AppUtils.get_device_id(context));
            jsonBody.put("device_type",           Constant.device_type);
            jsonBody.put("token",                 AppUtils.get_token(context));
            jsonBody.put("pageName",             "store");
            jsonBody.put("serviceName",          "isstore");

            jsonBody.put("member_id",            AppUtils.get_user_id(context));
            jsonBody.put("column_id",            ID);
            jsonBody.put("type",                 1);//收藏分类 1需求

        } catch (JSONException e) {
            e.printStackTrace();
        }
//        Logger.i(jsonBody.toString()+" ==["+Constant.URL_isstore+" ]");
        HttpUtils.http_post_string(Constant.URL_isstore,jsonBody.toString(),do_isstore);
    }

    StringCallback do_isstore = new StringCallback(){


        @Override
        public void onError(Call call, Exception e, int i) {
            if(hud.isShowing()){
                hud.dismiss();
            }
            Logger.e(e.getMessage());
        }

        @Override
        public void onResponse(String s, int i) {
            if(hud.isShowing()){
                hud.dismiss();
            }
//            Logger.e(s);
            try{
                isstore_bean data = new Gson().fromJson(s, isstore_bean.class);

                if(data.state !=1 ){
                    T.show(context,data.msg,0);
                }else{
                    if(data.data.status.equals("0")){//1：未收藏；0：已收藏
                        ck_store.setChecked(true);
                    }else{
                        ck_store.setChecked(false);
                    }
                }
            }catch (Exception e){
                e.printStackTrace();
                T.show(context,getResources().getString(R.string.alert_again),0);
            }
        }
    };

        private void toNet_addstore(){//是否收藏
        hud.show();
        JSONObject jsonBody=new JSONObject();
        try {
            jsonBody.put("device_number",         AppUtils.get_device_id(context));
            jsonBody.put("device_type",           Constant.device_type);
            jsonBody.put("token",                 AppUtils.get_token(context));
            jsonBody.put("pageName",             "store");
            jsonBody.put("serviceName",          "addstore");

            jsonBody.put("member_id",            AppUtils.get_user_id(context));
            jsonBody.put("id",                   ID);
            jsonBody.put("type",                 1);//1需求2服务商3商品

            if(ck_store.isChecked()){
                jsonBody.put("status",               1);// 	0添加收藏 1取消收藏
            }else{
                jsonBody.put("status",               0);// 	0添加收藏 1取消收藏
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
//        Logger.i(jsonBody.toString()+" ==["+Constant.URL_addstore+" ]");
        HttpUtils.http_post_string(Constant.URL_addstore,jsonBody.toString(),do_addstore);
    }

    StringCallback do_addstore = new StringCallback(){


        @Override
        public void onError(Call call, Exception e, int i) {
            if(hud.isShowing()){
                hud.dismiss();
            }
            Logger.e(e.getMessage());
        }

        @Override
        public void onResponse(String s, int i) {

//            Logger.e(s);
            try{
                isstore_bean data = new Gson().fromJson(s, isstore_bean.class);

                if(data.state !=1 ){
                    T.show(context,data.msg,0);
                }else{
                    toNet_isstore();
                }
            }catch (Exception e){
                e.printStackTrace();
                T.show(context,getResources().getString(R.string.alert_again),0);
            }
        }
    };


    ///////////////////////////////关闭需求
    private void toNet_closedemand(){
        hud.show();
        JSONObject jsonBody=new JSONObject();
        try {
            jsonBody.put("device_number",         AppUtils.get_device_id(context));
            jsonBody.put("device_type",           Constant.device_type);
            jsonBody.put("token",                 AppUtils.get_token(context));
            jsonBody.put("pageName",             "demand");
            jsonBody.put("serviceName",          "closedemand");

            jsonBody.put("member_id",             AppUtils.get_user_id(context));
            jsonBody.put("demand_id",             ID);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        Logger.i("do_getgoodslist = "+jsonBody.toString());
        HttpUtils.http_post_string(Constant.URL_closedemand,jsonBody.toString(),do_closedemand);
    }



    StringCallback do_closedemand = new StringCallback(){


        @Override
        public void onError(Call call, Exception e, int i) {
            Logger.e(e.getMessage());
        }

        @Override
        public void onResponse(String s, int i) {
            if(hud.isShowing()){
                hud.dismiss();
            }
            Logger.e("do_getgoodslist = "+s);
            try{
                normal data = new Gson().fromJson(s, normal.class);
                if(data.state !=1 ){
                    T.show(context,data.msg,0);
                }else{
                    EventBus.getDefault().post(new MessageEvent(Constant.ACTION_REFREASH_myneedlist));
                    T.show(context,getResources().getString(R.string.alert_success_do),1);
                    closeActivity();
                }
            }catch (Exception e){
                e.printStackTrace();
                T.show(context,getResources().getString(R.string.alert_again),0);
            }
        }
    };






    //    /////NET
    private void toNet_ykjtgorder(){
        hud.show();
        JSONObject jsonBody=new JSONObject();
        try {
            jsonBody.put("device_number",         AppUtils.get_device_id(context));
            jsonBody.put("device_type",           Constant.device_type);
            jsonBody.put("token",                 AppUtils.get_token(context));
            jsonBody.put("pageName",             "pay");
            jsonBody.put("serviceName",          "ykjtgorder");

            jsonBody.put("member_id",            AppUtils.get_user_id(context));
            jsonBody.put("demand_id",                   ID);


        } catch (JSONException e) {
            e.printStackTrace();
        }
//        Logger.i(jsonBody.toString()+" ==["+Constant.URL_demanddetail+" ]");
        HttpUtils.http_post_string(Constant.URL_ykjtgorder,jsonBody.toString(),do_ykjtgorder);
    }


    StringCallback do_ykjtgorder = new StringCallback(){


        @Override
        public void onError(Call call, Exception e, int i) {
            Logger.e(e.getMessage());
        }

        @Override
        public void onResponse(String s, int i) {
            if(hud.isShowing()){
                hud.dismiss();
            }
            Logger.e("需求详情"+s);
            try{
                ykjtgorder_bean data = new Gson().fromJson(s, ykjtgorder_bean.class);

                if(data.state !=1 ){
                    T.show(context,data.msg,0);
                }else{
                    if(data.data.bank == null){
                        Bundle dd = new Bundle();
                        dd.putString("order_id",data.data.order_id);
                        dd.putString("total_price",""+data.data.trust_amount);
                        dd.putInt("PAY_TYPE",1);
                        jumpActivity(Activity_pay_shopping.class,dd,true);
                    }else{
                        view5.setVisibility(View.VISIBLE);
                        show_info.setText(getResources().getString(R.string.alert_large_money)+"\n"+
                                data.data.bank.rank_name+"\n"+
                                data.data.bank.rank_account+"\n"+
                                data.data.bank.account_holder);
                    }
                }
            }catch (Exception e){
                e.printStackTrace();
                T.show(context,getResources().getString(R.string.alert_again),0);
            }
        }
    };

    private void toNet_complete(){//乙方完成
        hud.show();
        JSONObject jsonBody=new JSONObject();
        try {
            jsonBody.put("device_number",         AppUtils.get_device_id(context));
            jsonBody.put("device_type",           Constant.device_type);
            jsonBody.put("token",                 AppUtils.get_token(context));
            jsonBody.put("pageName",             "demand");
            jsonBody.put("serviceName",          "complete");

            jsonBody.put("demand_id",            ID );
            jsonBody.put("bid_id",                bid_id);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        Logger.i(jsonBody.toString()+" ==["+Constant.URL_complete+" ]");
        HttpUtils.http_post_string(Constant.URL_complete,jsonBody.toString(),do_complete);
    }

    StringCallback do_complete = new StringCallback(){


        @Override
        public void onError(Call call, Exception e, int i) {
            if(hud.isShowing()){
                hud.dismiss();
            }
            Logger.e(e.getMessage());
        }

        @Override
        public void onResponse(String s, int i) {

            Logger.e(s);
            try{
                complete_bean data = new Gson().fromJson(s, complete_bean.class);

                if(data.state !=1 ){
                    T.show(context,data.msg,0);
                }else{
                    T.show(context,getResources().getString(R.string.alert_waitforother_sure),0);
                    reload_myself();

                }
            }catch (Exception e){
                e.printStackTrace();
                T.show(context,getResources().getString(R.string.alert_again),0);
            }
        }
    };


    private void toNet_jiaconfirmpay(){//
        hud.show();
        JSONObject jsonBody=new JSONObject();
        try {
            jsonBody.put("device_number",         AppUtils.get_device_id(context));
            jsonBody.put("device_type",           Constant.device_type);
            jsonBody.put("token",                 AppUtils.get_token(context));
            jsonBody.put("pageName",             "demand");
            jsonBody.put("serviceName",          "jiaconfirmpay");

            jsonBody.put("demand_id",            ID );
            jsonBody.put("member_id",            AppUtils.get_user_id(context));
            jsonBody.put("stage_num",            stage_num );
        } catch (JSONException e) {
            e.printStackTrace();
        }
//        Logger.i(jsonBody.toString()+" ==["+Constant.URL_jiaconfirmpay+" ]");
        HttpUtils.http_post_string(Constant.URL_jiaconfirmpay,jsonBody.toString(),do_jiaconfirmpay);
    }


    StringCallback do_jiaconfirmpay = new StringCallback(){


        @Override
        public void onError(Call call, Exception e, int i) {
            if(hud.isShowing()){
                hud.dismiss();
            }
            Logger.e(e.getMessage());
        }

        @Override
        public void onResponse(String s, int i) {

            Logger.e(s);
            try{
                normal data = new Gson().fromJson(s, normal.class);

                if(data.state !=1 ){
                    T.show(context,data.msg,0);
                }else{
                    T.show(context,getResources().getString(R.string.alert_success_do),0);
                    reload_myself();

                }
            }catch (Exception e){
                e.printStackTrace();
                T.show(context,getResources().getString(R.string.alert_again),0);
            }
        }
    };

    private void toNet_tuoguanorder(String budget_amount){
        hud.show();
        JSONObject jsonBody=new JSONObject();
        try {
            jsonBody.put("device_number",         AppUtils.get_device_id(context));
            jsonBody.put("device_type",           Constant.device_type);
            jsonBody.put("token",                 AppUtils.get_token(context));
            jsonBody.put("pageName",             "pay");
            jsonBody.put("serviceName",          "tuoguanorder");

            jsonBody.put("member_id",            AppUtils.get_user_id(context));
            jsonBody.put("demand_id",                   ID);

            jsonBody.put("bid_id",                bid_id);
            jsonBody.put("stage_num",             stage_num);

            if(stage_pay_status == 0 ){//0未支付1已支付
               jsonBody.put("budget_amount",         0);
            }else{
               jsonBody.put("budget_amount",         budget_amount);
            }


        } catch (JSONException e) {
            e.printStackTrace();
        }
        Logger.i(jsonBody.toString()+" ==["+Constant.URL_tuoguanorder+" ]");
        HttpUtils.http_post_string(Constant.URL_tuoguanorder,jsonBody.toString(),do_tuoguanorder);
    }


    StringCallback do_tuoguanorder = new StringCallback(){


        @Override
        public void onError(Call call, Exception e, int i) {
            Logger.e(e.getMessage());
        }

        @Override
        public void onResponse(String s, int i) {
            if(hud.isShowing()){
                hud.dismiss();
            }
            Logger.e("do_tuoguanorder"+s);
            try{
                tuoguanorder_bean data = new Gson().fromJson(s, tuoguanorder_bean.class);

                if(data.state !=1 ){
                    T.show(context,data.msg,0);
                }else{

                    Bundle b = new Bundle();
                    b.putString("order_id",   data.data.order_id);
                    b.putString("total_price",data.data.trust_amount);
                    b.putInt("PAY_TYPE",1);
                    jumpActivity(Activity_pay_shopping.class,b,false);
                }
            }catch (Exception e){
                e.printStackTrace();
                T.show(context,getResources().getString(R.string.alert_again),0);
            }
        }
    };

}
